home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 955 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: vandevod@cs.rpi.edu (David Vandevoorde)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Const class member
  5. Date: 03 Apr 1996 09:22:55 PST
  6. Organization: RPI Computer Science
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <xsolokd1gum.fsf@avs.cs.rpi.edu>
  9. References: <4jgpqa$t09@nntp.interaccess.com>
  10.     <4jq60l$6pp@symiserver2.symantec.com>
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 03 Apr 1996 10:12:49 -0500
  13. In-Reply-To: thoff@symantec.com's message of 02 Apr 96 13:30:31 GMT
  14. X-Newsreader: Gnus v5.1
  15. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  16.     iQBVAwUBMWKz8Ey4NqrwXLNJAQGmvgH/awUOAD0g/s1q5E/GJ6u7WqOaW/3msCkf
  17.     /EX+WEKScnKz2g5XUa9MgUt30upNa68A9KGfqPEFIid4srlPKbMp4Q==
  18.     =IwNo
  19. Originator: austern@isolde.mti.sgi.com
  20.  
  21. >>>>> "TH" == Torsten Hoff <thoff@symantec.com> writes:
  22. [...]
  23. TH> If you *really* want compile-time initialized constants, and can live
  24. TH> with something that has essentially the same properties as an integer,
  25. TH> use class-scope enums. If you need several compile-time constants with
  26. TH> the same value, you can use multiple untagged enums:
  27.  
  28. TH> class AnyClass
  29. TH> {
  30. TH>     enum {FOO = 1, BAR = 1}; // multiple enums with same value; 
  31.                                  //    doesn't work!
  32. TH>     enum {FOO = 1};          // OK
  33. TH>     enum {BAR = 1};          // OK
  34. TH> }
  35. [...]
  36.  
  37. Alternatively:
  38.  
  39.     struct AnyStruct {
  40.         static bool const Yes = true;
  41.         static char const A = 'B';
  42.     };
  43.  
  44. (Somewhere:
  45.     bool const AnyStruct::Yes;
  46.     char const AnyStruct::A;
  47. )
  48.  
  49. which works for integral types (if you compiler is reasonably up-to-date).
  50.  
  51.     Daveed
  52. ---
  53. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  54.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  55.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  56.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  57.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  58. ]
  59.